package com.donggua.aichebao.commonui.Dialog;

import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.donggua.aichebao.commonui.R;

/**
 * Created by Administrator on 2017-09-12.
 */

public abstract  class DGPopupwindow extends PopupWindow {
    protected Activity mActivity;
    protected View mMainView;
    public DGPopupwindow(Activity activity){
        super(activity);
        mActivity = activity;
        mMainView = getView();
        setFocusable(true);
        setOutsideTouchable(true);
        setBackgroundDrawable(mActivity.getResources().getDrawable(R.drawable.white));
        init();
        setContentView(mMainView);
    }

    protected void init(){
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    }


    protected abstract View getView();

    public void show(View view){
        if(!isShowing()){
            this.showAsDropDown(view);
        }
    }

    public void showInCenter(){
        if(!isShowing()){
            this.showAtLocation(mMainView,Gravity.CENTER,0,0);
        }
    }

    public void close(){
        if(isShowing()){
            this.dismiss();
        }
    }
}
